<?php
namespace app\common\model;

use think\model\concern\SoftDelete;

class User extends Model
{
    use SoftDelete;

    protected $name = 'user';
    protected $autoWriteTimestamp = true;

    //可搜索字段
    protected $searchField = ['username', 'mobile', 'nickname'];

    // 属性获取器

    //是否启用用户体验收益资格
    public function getExperienceTextAttr($value, $data): string
    {
        return self::EXPERIENCE_TEXT[$data['is_experience']];
    }
    //是否启用获取器
    public function getStatusTextAttr($value, $data): string
    {
        return self::BOOLEAN_TEXT[$data['status']];
    }

    //用户等级
    public function getUserLevelIdTextAttr($value, $data): string
    {
        return self::LEVEL_TEXT[$data['user_level_id']];
    }

    // 关联用户等级
//    public function userLevel(): \think\model\relation\BelongsTo
//    {
//        return $this->belongsTo(UserLevel::class);
//    }

    // 获取用户信息
    public static function getUserInfo($userId): array
    {
        return self::field('id, nickname, avatar, mobile')
            ->findOrEmpty($userId)
            ->toArray();
    }
}